/**
 * @param {number[][]} graph
 * @return {number[][]}
 */
var allPathsSourceTarget = function (graph) {
    let res = []
    pathLevel(graph, 0, res, [0])
    return res
};

function pathLevel(graph, level, res, valArr) {
    if (level === graph.length - 1) {
        res.push(valArr.slice(0))
        return
    }
    for (let i = 0; i < graph[level].length; i++) {
        valArr.push(graph[level][i])
        pathLevel(graph, graph[level][i], res, valArr)
        valArr.pop()
    }
}




const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    line = await readline()
    // 创建邻接矩阵
    let [m, n] = line.split(' ').map((i)=>parseInt(i)),
        graph = new Array(m + 1).fill(0).map(() => new Array(m + 1).fill(0)),
        res = [];
    while (line = await readline()) {
        let [a, b] = line.split(' ').map((i) => parseInt(i));
        graph[a][b] = 1
    }
    dfs(graph, 1, res, [1])
    for (let item of res) {
        console.log(item.join(" "))
    }
}()

function dfs(graph, index, res, valArr) {
    if (index === graph.length - 1) {
        res.push(valArr.slice())
        return
    }

    for (let i = 1; i <= graph[index].length; i++) {
        if (graph[index][i] === 1) {
            valArr.push(i)
            dfs(graph, i, res, valArr)
            valArr.pop()
        }
    }
}

// 邻接矩阵
[
    [ 0, 0, 0, 0, 0, 0 ],
    [ 0, 0, 1, 1, 0, 0 ],   节点1可以到达2和3
    [ 0, 0, 0, 0, 1, 0 ],
    [ 0, 0, 0, 0, 0, 1 ],
    [ 0, 0, 0, 0, 0, 1 ],
    [ 0, 0, 0, 0, 0, 0 ]
]


void async function () {
    line = await readline()
    // 创建邻接表
    let [m, n] = line.split(' ').map((i)=>parseInt(i)),
        graph = new Array(m + 1).fill(0).map(() => new Array()),
        res = [];
    while (line = await readline()) {
        let [a, b] = line.split(' ').map((i) => parseInt(i));
        graph[a].push(b)
    }
    dfs(graph, 1, res, [1])
    for (let item of res) {
        console.log(item.join(" "))
    }
}()

function dfs(graph, index, res, valArr) {
    if (index === graph.length - 1) {
        res.push(valArr.slice())
        return
    }

    let toArr = graph[index]

    for (let item of toArr) {
        valArr.push(item)
        dfs(graph, item, res, valArr)
        valArr.pop()
    }

}

// 邻接表
[ [], [ 3, 2 ], [ 4 ], [ 5 ], [ 5 ], [] ]